//
//  LineNaviCustomView.swift
//  FrameProduct
//
//  Created by delegate on 2025/10/21.
//

import UIKit

class LineNaviCustomView: UIView {
    var normalNoteButtonActionBlock: (() -> Void)?
    var advancedNoteButtonActionBlock: (() -> Void)?
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    private func setupUI() {
        addSubviews(normalNoteButton, advancedNoteButton, blueLineView)
        normalNoteButton.snp.makeConstraints { make in
            make.top.equalToSuperview()
            make.bottom.equalToSuperview()
            make.right.equalTo(self.snp.centerX).offset(-29)
            make.left.equalToSuperview()
            make.width.equalTo(72)
        }
        advancedNoteButton.snp.makeConstraints { make in
            make.top.equalToSuperview()
            make.bottom.equalToSuperview()
            make.left.equalTo(self.snp.centerX).offset(29)
            make.right.equalToSuperview()
            make.width.equalTo(72)
        }
        blueLineView.snp.makeConstraints { make in
            make.centerX.equalTo(normalNoteButton.snp.centerX)
            make.width.equalTo(27)
            make.height.equalTo(2)
            make.bottom.equalToSuperview()
        }
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //=================================================================
    //                           事件处理
    //=================================================================
    // MARK: - 事件处理
    @objc private func normalNoteButtonAction() {
        normalNoteButton.isSelected = true
        advancedNoteButton.isSelected = false
        blueLineView.snp.remakeConstraints { make in
            make.centerX.equalTo(normalNoteButton.snp.centerX)
            make.bottom.equalToSuperview()
            make.width.equalTo(60)
            make.height.equalTo(2)
        }
        normalNoteButtonActionBlock?()
    }
    @objc private func advancedNoteButtonAction() {
        normalNoteButton.isSelected = false
        advancedNoteButton.isSelected = true
        blueLineView.snp.remakeConstraints { make in
            make.centerX.equalTo(advancedNoteButton.snp.centerX)
            make.bottom.equalToSuperview()
            make.width.equalTo(60)
            make.height.equalTo(2)
        }
        advancedNoteButtonActionBlock?()
        
    }
    //=================================================================
    //                            lazy
    //=================================================================
    // MARK: - lazy
    private lazy var normalNoteButton: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitle("普通节点", for: .normal)
        button.setTitle("普通节点", for: .selected)
        button.setTitleColor(.lxs.hex("#808080"), for: .normal)
        button.setTitleColor(.lxs.hex("#FFFFFF"), for: .selected)
        button.titleLabel?.font = .lxs.font(size: 18)
        button.addTarget(self, action: #selector(normalNoteButtonAction), for: .touchUpInside)
        button.isSelected = true
        return button
    }()
    private lazy var advancedNoteButton: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitle("高级节点", for: .normal)
        button.setTitle("高级节点", for: .selected)
        button.setTitleColor(.lxs.hex("#808080"), for: .normal)
        button.setTitleColor(.lxs.hex("#FFFFFF"), for: .selected)
        button.titleLabel?.font = .lxs.font(size: 18)
        button.addTarget(self, action: #selector(advancedNoteButtonAction), for: .touchUpInside)
        button.isSelected = false
        return button
    }()
    private lazy var blueLineView: UIView = {
        let lineView = UIView()
        lineView.backgroundColor = .lxs.hex("#57A0FF")
        return lineView
    }()
}
